CREATE PROCEDURE egTeleSave
(
	@id						int output,
	@Name					nvarchar(500),
	@Tel					nvarchar(50),
	@State					int,
	@Notes					ntext,
	@ApprovalHistory		ntext,
	@FK_WorkflowDefinition	int
)
AS

IF @id = -1
BEGIN
	SET NOCOUNT ON;
	INSERT INTO TelephoneBook ([Name], Tel, State, Notes, ApprovalHistory, FK_WorkflowDefinition) VALUES
		(@Name, @Tel, @State, @Notes, @ApprovalHistory, @FK_WorkflowDefinition);
	SET NOCOUNT OFF;
	
	SELECT @id = @@IDENTITY;
END
ELSE
BEGIN
	UPDATE TelephoneBook SET
		[Name] = @Name,
		Tel = @Tel,
		State = @State,
		Notes = @Notes,
		ApprovalHistory = @ApprovalHistory,
		FK_WorkflowDefinition = @FK_WorkflowDefinition
	WHERE PK_ID=@id;
END
